//
//  HomeMenueView.m
//  GiftNote
//
//  Created by lanou on 15/8/11.
//  Copyright (c) 2015年 GN. All rights reserved.
//

#import "HomeMenueView.h"

@interface HomeMenueView ()

@property (nonatomic, assign)CGRect beforeFrame;
@property (nonatomic, assign)CGRect afterFrame;


@end

@implementation HomeMenueView

- (instancetype)initWithFrame:(CGRect)frame array:(NSArray *)array
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _isShow = NO;
        _daraSource = array;
        _beforeFrame = frame;
        _afterFrame = frame;
        _afterFrame.size.height = 0;
        
        _tableView = [[UITableView alloc]initWithFrame:_afterFrame];
        _tableView.backgroundColor = [UIColor yellowColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        [self addSubview:_tableView];
        _tableView.bounces = NO;
        
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _daraSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = _daraSource[indexPath.row];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.backgroundColor = [UIColor blackColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_delegate && [_delegate respondsToSelector:@selector(transportMenuName:index:)]) {
        [_delegate transportMenuName:_daraSource[indexPath.row] index:indexPath.row];
    }
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [UIView animateWithDuration:0.3 animations:^{
        _tableView.frame = _afterFrame;
        _isShow = NO;
    }];
}

- (void)menuShow:(UINavigationController *)naVC
{
    [naVC.view insertSubview:_tableView aboveSubview:naVC.navigationBar];
    
    [UIView animateWithDuration:0.3 animations:^{
        _tableView.frame = _beforeFrame;
    }];
    
    _isShow = YES;
    
}

- (void)menuDismiss
{
    [UIView animateWithDuration:0.3 animations:^{
        _tableView.frame = _afterFrame;
    }];
    
    _isShow = NO;
}

@end












